import Vue from 'vue'
import Router from 'vue-router'
import example from './example'

const layout = () => import('@/components/layout/layout'),
    exampleLayout = () => import('@/components/layout/example-layout'),
    index = () => import('@/page/index'),
    login = () => import('@/page/login'),

    patientManage = () => import('@/page/patient-manage'),
    patientDetail = () => import('@/page/patient-detail'),
    accompanyManage = () => import('@/page/accompany-manage'),
    visitorsManage = () => import('@/page/visitors-manage'),
    accountManage = () => import('@/page/account-manage'),
    passwordEdit = () => import('@/page/password-edit'),
    appointmentSetting = () => import('@/page/appointment-setting'),
    temporaryCard = () => import('@/page/temporary-card'),
    home = () => import('@/page/home'),
    backlog = () => import('@/page/backlog'),
    punchCard = () => import('@/page/punch-card'),
    map = () => import('@/page/map'),
    mapDetail = () => import('@/page/map-detail'),

    // 初始路由集
    constantRouterMap = [
        {
            path: '/401',
            name: '401',
            component: layout
        },
        {
            path: '/',
            name: 'index',
            component: index
            // redirect: '/monitor/home'
        },
        {
            path: '/login',
            name: 'login',
            component: login
        },
        {
            path: '/monitor',
            name: 'monitor',
            component: layout,
            children: [
                {
                    path: 'patient-manage',
                    name: 'patientManage',
                    component: patientManage,
                    meta: {
                        title: '患者管理',
                        auth: 3
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'patientDetail',
                            component: patientDetail,
                            meta: {
                                title: '患者详情',
                                auth: 3
                            }
                        }
                    ]
                },
                {
                    path: 'accompany-manage',
                    name: 'accompanyManage',
                    component: accompanyManage,
                    meta: {
                        title: '陪护管理',
                        auth: 3
                    }
                },
                {
                    path: 'visitors-manage',
                    name: 'visitorsManage',
                    component: visitorsManage,
                    meta: {
                        title: '探视管理',
                        auth: 3
                    }
                },
                {
                    path: 'account-manage',
                    name: 'accountManage',
                    component: accountManage,
                    meta: {
                        title: '后台账户管理',
                        auth: 2
                    }
                },
                {
                    path: 'password-edit',
                    name: 'passwordEdit',
                    component: passwordEdit,
                    meta: {
                        title: '密码管理'
                    }
                },
                {
                    path: 'appointment-setting',
                    name: 'appointmentSetting',
                    component: appointmentSetting,
                    meta: {
                        title: '预约设置',
                        auth: 2
                    }
                },
                {
                    path: 'temporary-card',
                    name: 'temporaryCard',
                    component: temporaryCard,
                    meta: {
                        title: '临时卡管理',
                        auth: 4
                    }
                },
                {
                    path: 'punch-card',
                    name: 'punchCard',
                    component: punchCard,
                    meta: {
                        title: '健康打卡',
                        auth: 3
                    }
                },
                {
                    path: 'map',
                    name: 'map',
                    component: map,
                    meta: {
                        title: '虚拟地图',
                        auth: 3
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'mapDetail',
                            component: mapDetail,
                            meta: {
                                title: '房间详情',
                                auth: 3
                            }
                        }
                    ]
                },
                {
                    path: 'home',
                    name: 'home',
                    component: home,
                    meta: {
                        title: '今日医院',
                        auth: 3
                    },
                    children: [
                        {
                            path: 'backlog',
                            name: 'backlog',
                            component: backlog,
                            meta: {
                                title: '待办事项',
                                auth: 3
                            }
                        }
                    ]
                }
            ]
        }
    ],
    layoutRouter = []

/*
* 开发环境添加example示例路由，可跳转查看组件如何使用
* 上线时将这一段注释
*/
if (process.env.NODE_ENV !== 'production') {
    constantRouterMap.push({
        path: '/example',
        name: 'example',
        component: exampleLayout,
        meta: {
            title: '控件示例'
        },
        children: []
    })
    constantRouterMap[constantRouterMap.length - 1].children.unshift(...example)
}

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // 页面跳转更改浏览器标题
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router

export {
    layoutRouter
}
